import Vue from 'vue'
import { sessionStore } from 'store/dist/store.legacy'
const state = {
  list: [],
  url: process.env.VUE_APP_typeList_url,
}

const mutations = {
  setList (state, param) {
    sessionStore.set('typeList', param.data)
    state.list = param.data
  }
}

const actions = {
  setList ({ state, commit }) {
    let list = state.list
    console.log('fff', list.length)
    if (list.length == 0) {
      list = sessionStore.get('typeList') || {}
    }
    console.log('list111', [])
    if (list.length == 0) {
      console.log(state.url)
      window.axios(state.url).then(ret => {
        commit('setList', { data: ret.data })
      })
    } else {
      commit('setList', { data: list })
    }
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}